<!-- 搜索表单 -->
<template>
  <el-form label-width="100px"
           class="ele-form-search"
           ref="form"
           @keyup.enter.native="search"
           @submit.native.prevent>
    <el-row :gutter="15">
      <el-col :lg="6"
              :md="12">
        <el-form-item label="推广员姓名:">
          <el-input clearable
                    v-model="where.name"
                    placeholder="请输入推广员姓名" />
        </el-form-item>
      </el-col>

      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 8 }">
        <el-form-item label="冻结状态:"
                      prop="state">
          <el-select clearable
                     class="ele-block"
                     v-model="where.state"
                     placeholder="请选择冻结状态">
            <el-option label="正常"
                       :value="1" />
            <el-option label="禁用"
                       :value="2" />

          </el-select>
        </el-form-item>
      </el-col>
      <el-col :lg="6"
              :md="12">
        <el-form-item label="账号:">
          <el-input clearable
                    v-model="where.account"
                    placeholder="请输入推广员账号" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 8 }">
        <el-form-item label="创建时间:"
                      prop="dateRange">
          <el-date-picker v-model="where.dateRange"
                          type="datetimerange"
                          unlink-panels
                          range-separator="至"
                          start-placeholder="开始时间"
                          end-placeholder="结束时间"
                          :default-time="['00:00:00', '23:59:59']"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          class="ele-fluid" />
        </el-form-item>
      </el-col>
      <el-col :lg="6"
              :md="12">
        <div class="ele-form-actions">
          <el-button type="primary"
                     icon="el-icon-search"
                     class="ele-btn-icon"
                     @click="search">
            查询
          </el-button>
          <el-button @click="reset('form')">重置</el-button>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
const DEFAULT_WHERE = {
  name: '',
  account: "",
  state: "",

  dateRange: [],
};

export default {
  name: 'RoleSearch',
  data () {
    return {
      // 表单数据
      where: { ...DEFAULT_WHERE },
      sumbitForm: {}



    };
  },
  methods: {
    /* 搜索 */
    search () {
      for (const key in this.where) {
        if (key == 'dateRange') {
          let startTime = this.where[key]?.[0];
          let endTime = this.where[key]?.[1];
          this.sumbitForm['start_create_time'] =
            startTime == undefined ? '' : startTime;
          this.sumbitForm['end_create_time'] =
            endTime == undefined ? '' : endTime;
        } else if (key == 'orderAmount') {
          this.sumbitForm['startOrderAmount'] =
            this.where[key].startOrderAmount == undefined
              ? ''
              : this.where[key].startOrderAmount;
          this.sumbitForm['endOrderAmount'] =
            this.where[key].endOrderAmount == undefined
              ? ''
              : this.where[key].endOrderAmount;
        } else {
          this.sumbitForm[key] = this.where[key];
        }
      }

      //   console.log(this.sumbitForm)
      this.$emit('search', this.sumbitForm);
    },
    /*  重置 */
    reset (formName) {
      this.$refs[formName].resetFields();

      this.where = {}
      this.sumbitForm = {};

      this.$emit('search', this.sumbitForm);
    }
  }
};
</script>
